<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
                    <script type="text/javascript" src="lib/html5shiv.js"></script>
                    <script type="text/javascript" src="lib/respond.min.js"></script>
                    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <!--[if IE 6]>
                    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
                    <script>DD_belatedPNG.fix('*');</script>
                    <![endif]-->
    <title>礼包管理</title>
</head>

<body>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 礼包管理 <span
            class="c-gray en">&gt;</span>
        礼包列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
            title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20" style="border:0;background:none"> <span class="l"></span> </div>
        <table class="layui-hide" id="giftBag" lay-filter="giftBag"></table>
    </div>
    <input type="" name="details_id" id="details_id" value="" style="display:none;" />
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./../static/js/common.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript" src="./../lib/layui/layui.js"></script>
    <script type="text/html" id="operation">
        <a  title="编辑" lay-event="edit" class=""><i class="Hui-iconfont">&#xe6df;</i></a>
       
    </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#giftBag',
                cellMinWidth: 80,
                url: admin_url + '/kvmUserLv/lvList',
                // id为重置表格，进行搜索
                id: 'reload',
                request: {
                    pageName: 'page',
                    limitName: 'size'
                },
                // // 传输模式
                // // contentType: 'application/json',
                paresData: function (res) {
                    return {
                        'data': res.data
                    }
                },
                response: {
                    statusCode: 200
                },
                // // // 传入数据
                where: {
                    tokenUserId: userId,
                    token: token
                },
                // // 回调
                done: function (res, curr, count) {
                    // 显示重销比率暂时注释
                    // var item = '';
                    // var dv = '';
                    // for (var i = 0; i < res.data.length; i++) {
                    //     var second = eval(res.data[i].second);
                    //     for (var k = 0; k < second.length; k++) {
                    //         if (second[k].lv == 0) {
                    //             item = '<span>大众会员</span>'
                    //         } else if (second[k].lv == 1) {
                    //             item = '<span>黄金会员</span>'
                    //         } else if (second[k].lv == 2) {
                    //             item = '<span>铂金会员</span>'
                    //         } else if (second[k].lv == 3) {
                    //             item = '<span>钻石会员</span>'
                    //         }
                    //         dv += item + ':<span>' + second[k].point + '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    //     }
                    //     $("td[data-field='second']").eq(i).html(dv + ' <a  title="修改重销比例" lay-event="edit-cx" class=""><i class="Hui-iconfont">&#xe647;</i></a>');
                    //     dv = '';
                    // }
                },
                method: 'post',
                page: 'true',
                cols: [[
                    { checkbox: true, align: 'center' },
                    {
                        field: 'lv', title: '等级名称', align: 'center', templet: function (obj) {

                            if (obj.lv == 0) {
                                return '<span>大众会员</span>'
                            } else if (obj.lv == 1) {
                                return '<span>黄金会员</span>'
                            } else if (obj.lv == 2) {
                                return '<span>铂金会员</span>'
                            } else if (obj.lv == 3) {
                                return '<span>钻石会员</span>'
                            }
                        }
                    },
                    { field: 'point', title: '折扣', align: 'center' },
                    { field: 'amount', title: '最大返利金额', align: 'center' },

                    // {
                    //     field: 'second', title: '返利比率', align: 'center', width: 326
                    // },
                    { toolbar: '#operation', title: '操作', align: 'center' }
                ]]
            })
            // 监听行操作栏事件。。可直接传值..
            table.on('tool(giftBag)', function (obj) {
                var id = obj.data.id;
                second = eval(obj.data.second),
                    leng = second.length,
                    lv = obj.data.lv;

                if (obj.event == 'edit') {
                    var index = layer.open({
                        type: 2,
                        id: id,
                        title: '礼包内容修改',
                        content: './giftBagLvEdit.html'
                    })
                    layer.full(index);
                    //   传输id值.
                    $("#details_id").val(id)
                } else if (obj.event == 'edit-cx') {
                    var member = '';
                    var arr = [],
                        reSaleLv = [];
                    for (var i = 0; i < leng; i++) {
                        if (second[i].lv == 0) {
                            member = '<span>大众会员</span>';
                            reSaleLv.push(second[i].lv)
                        } else if (second[i].lv == 1) {
                            member = '<span>黄金会员</span>'
                            reSaleLv.push(second[i].lv)
                        } else if (second[i].lv == 2) {
                            member = '<span>铂金会员</span>'
                            reSaleLv.push(second[i].lv)
                        } else if (second[i].lv == 3) {
                            member = '<span>钻石会员</span>'
                            reSaleLv.push(second[i].lv);
                        }
                    }
                    if (lv == 0) {
                        layer.confirm('<div><label>' + member + '</label><input class="input-text" type="number" id = "point" value = "' + second[0].point + '" style ="width:70%;display:inline-block" /> </div>', { title: '修改重销比例' }, function () {
                            var point = Number($("#point").val());
                            var arr = { id: id, data: [] };
                            for (var i = 0; i < reSaleLv.length; i++) {
                                obj = { lv: reSaleLv[i], point: point };
                            }
                            for (var i = 0; i < leng; i++) {
                                arr.data.push(obj)
                            }
                            var reSale = JSON.stringify(arr)
                            $.ajax({
                                type: 'post',
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmUserLv/updateLvSecond',
                                data: { tokenUserId: userId, token: token, json: reSale },
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('设置成功', {
                                            time: 1000,
                                            end: function () {
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg, {
                                            time: 1500
                                        })
                                    }
                                },
                            })
                        })
                    } else if (lv == 1) {
                        layer.confirm('<div><label>大众会员：</label><input class="input-text" type="number" id = "point" value = "' + second[0].point + '" style ="width:70%;display:inline-block" /> </div>', { title: '修改重销比例' }, function () {
                            var point = Number($("#point").val());
                            var arr = { id: id, data: [] };
                            for (var i = 0; i < reSaleLv.length; i++) {
                                obj = { lv: reSaleLv[i], point: point };
                            }
                            for (var i = 0; i < leng; i++) {
                                arr.data.push(obj)
                            }
                            var reSale = JSON.stringify(arr)
                            $.ajax({
                                type: 'post',
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmUserLv/updateLvSecond',
                                data: { tokenUserId: userId, token: token, json: reSale },
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('设置成功', {
                                            time: 1000,
                                            end: function () {
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg, {
                                            time: 1500
                                        })
                                    }
                                },
                            })
                        })
                    } else if (lv == 2) {
                        layer.confirm('<div><label>大众会员：</label><input class="input-text point" type="number" value = "' + second[0].point + '" style ="width:70%;" /> <div style = "margin-top:10px;"><label>黄金会员：</label><input class="input-text point" type="number" value = "' + second[1].point + '" style ="width:70%;display:inline-block" /></div></div>', { title: '修改重销比例' }, function () {
                            var arr = { id: id, data: [] };
                            for (var i = 0; i < reSaleLv.length; i++) {
                                obj = { lv: reSaleLv[i], point: $(".point").eq(i).val() };
                                arr.data.push(obj)
                            }
                            var reSale = JSON.stringify(arr)
                            $.ajax({
                                type: 'post',
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmUserLv/updateLvSecond',
                                data: { tokenUserId: userId, token: token, json: reSale },
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('设置成功', {
                                            time: 1000,
                                            end: function () {
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg, {
                                            time: 1500
                                        })
                                    }
                                },
                            })
                        })
                    } else if (lv == 3) {
                        layer.confirm('<div><label>大众会员：</label><input class="input-text point" type="number" value = "' + second[1].point + '" style ="width:70%;" /> <div style = "margin-top:10px;"><label>黄金会员：</label><input class="input-text point" type="number" value = "' + second[2].point + '" style ="width:70%;display:inline-block" /></div> <div style = "margin-top:10px;"><label>钻石会员：</label><input class="input-text point" type="number" value = "' + second[0].point + '" style ="width:70%;display:inline-block" /></div></div>', { title: '修改重销比例' }, function () {
                            var arr = { id: id, data: [] };
                            for (var i = 0; i < reSaleLv.length; i++) {
                                obj = { lv: reSaleLv[i], point: $(".point").eq(i).val() };
                                arr.data.push(obj)
                            }
                            var reSale = JSON.stringify(arr)
                            $.ajax({
                                type: 'post',
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmUserLv/updateLvSecond',
                                data: { tokenUserId: userId, token: token, json: reSale },
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('设置成功', {
                                            time: 1000,
                                            end: function () {
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg, {
                                            time: 1500
                                        })
                                    }
                                },
                            })

                        })
                    }
                }
            })

        })
    </script>
</body>

</html>